package com.emep.changzhi.analyse.http.information;

import com.emep.changzhi.analyse.entity.information.DataMessageRecordWarning;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.information.DataMessageRecordWarningService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author Wangcc
 * @version V1.0
 * @Description: 消息推送记录控制器
 * @date 2018/2/27 17:19
 */
@RestController("datamessagerecordwarning")
@RequestMapping
@Api(value = "消息推送记录Controller",tags = "消息推送记录")
public class DataMessageRecordWarningController {

    @Autowired
    private DataMessageRecordWarningService dataMessageRecordWarningService;



    /**
     * 新增消息推送记录
     * @param payload
     * @return
     */
    @ApiOperation(value="新增消息推送记录", notes="新增消息推送记录")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateId", value = "模版id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "areaCode", value = "行政区划", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "PromptId", value = "报警信息id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "equipmentId", value = "设备id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "sendDate", value = "发送时间", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pushContent", value = "推送内容", required = true, dataType = "String",paramType="query")
    })
    @PostMapping(value = "add")
    public ResultBean<DataMessageRecordWarning> add(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "templateId",
           "areaCode","PromptId","equipmentId","sendDate","pushContent");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.boolAdd(dataMessageRecordWarningService.save(payload)) ;
        }
        return  result;
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="首页", notes="首页")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "home")
    public ResultBean<List<DataMessageRecordWarning>> findDataMessageRecordWarningByHome(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return result.ok(dataMessageRecordWarningService.findDataMessageRecordWarningByHome(Integer.parseInt(payload.get("pageSize").toString())));
        }
        return  result;
    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="翻页查询", notes="翻页查询")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),


            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "查询起始id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "Integer",paramType="query")
    })
    @GetMapping(value = "flip")
    public ResultBean<List<DataMessageRecordWarning>> findDataMessageRecordWarningByFlip(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "id","pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.ok(dataMessageRecordWarningService.findDataMessageRecordWarningByFlip(payload.get("id").toString() , Integer.parseInt(payload.get("pageSize").toString())));
        }
        return result;
    }

}
